package com.blrs.service.communication.impl;

import java.util.List;

import com.blrs.common.utils.ReflectionUtils;
import com.blrs.common.utils.SecurityUtils;
import com.blrs.service.communication.ICommunicationService;
import com.blrs.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.blrs.mapper.CommunicationMapper;
import com.blrs.domain.Communication;

/**
 * 往来信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-01
 */
@Service
public class CommunicationServiceImpl implements ICommunicationService
{
    @Autowired
    private CommunicationMapper communicationMapper;
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询往来信息
     * 
     * @param id 往来信息主键
     * @return 往来信息
     */
    @Override
    public Communication selectCommunicationById(String id)
    {
        return communicationMapper.selectCommunicationById(id);
    }

    /**
     * 查询往来信息列表
     * 
     * @param communication 往来信息
     * @return 往来信息
     */
    @Override
    public List<Communication> selectCommunicationList(Communication communication)
    {
        communication.setBelongTo(SecurityUtils.getOrgId());
        return communicationMapper.selectCommunicationList(communication);
    }

    /**
     * 新增往来信息
     * 
     * @param communication 往来信息
     * @return 结果
     */
    @Override
    public int insertCommunication(Communication communication) throws NoSuchFieldException, IllegalAccessException {
        ReflectionUtils.setCommonPrivateProperty(communication);
         communication.setBelongTo(SecurityUtils.getOrgId());
        communication.setOrganizationName(SecurityUtils.getOrgName());
        communication.setStatus("未完结");
        return communicationMapper.insertCommunication(communication);
    }

    /**
     * 修改往来信息
     * 
     * @param communication 往来信息
     * @return 结果
     */
    @Override
    public int updateCommunication(Communication communication)
    {
        return communicationMapper.updateCommunication(communication);
    }

    /**
     * 批量删除往来信息
     * 
     * @param ids 需要删除的往来信息主键
     * @return 结果
     */
    @Override
    public int deleteCommunicationByIds(String[] ids)
    {
        return communicationMapper.deleteCommunicationByIds(ids);
    }

    /**
     * 删除往来信息信息
     * 
     * @param id 往来信息主键
     * @return 结果
     */
    @Override
    public int deleteCommunicationById(String id)
    {
        return communicationMapper.deleteCommunicationById(id);
    }

    @Override
    public int confirmCommunication(String id) {
        Communication communication = new Communication();
        communication.setConfirmId(SecurityUtils.getUserId());
        communication.setConfirmName(SecurityUtils.getLoginUser().getUser().getNickName());
        communication.setId(id);
        return communicationMapper.updateCommunicationStatus(communication);
    }
}
